package com.fecean.aabbc.netty.server.init;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.util.CharsetUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * ServerChannelInitializer
 *
 * @author: chenfenghai
 * @version: 1.0
 * @date: 2020-02-24 10:09
 * @blame Team
 */
@Component
public class ServerChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Resource
    NettyServerHandler nettyServerHandler;

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        //添加编解码
        socketChannel.pipeline().addLast("decoder", new StringDecoder(CharsetUtil.UTF_8));
        socketChannel.pipeline().addLast("encoder", new StringEncoder(CharsetUtil.UTF_8));
        socketChannel.pipeline().addLast(nettyServerHandler);
    }
}
